package com.singletonapps.evory.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.singletonapps.evory.dto.ResponseDto;

@Controller
public class InicioController {
    
    private static final Logger LOGGER = LogManager.getLogger(InicioController.class.getName());
    
    @RequestMapping("/")
    public String pageIndex(ModelMap map){
        LOGGER.info("Se llego al index");
        map.put("menuActivo", "mnuHome");
        return "index";
    }

    @RequestMapping("/nosotros")
    public String pageAboutUs(ModelMap map){
        map.put("menuActivo", "mnuNosotros");
        return "about-us";
    }

    @RequestMapping("/servicios")
    public String pageServices(ModelMap map){
        map.put("menuActivo", "mnuServicios");
        return "services";
    }
    
    @RequestMapping("/cursos")
    public String pageCourses(ModelMap map){
        map.put("menuActivo", "mnuCursos");
        return "courses";
    }
    
    @RequestMapping("/contacto")
    public String pageContact(ModelMap map){
        map.put("menuActivo", "mnuContactanos");
        return "contact-us";
    }
    
    @RequestMapping("/blog")
    public String pageBlog(ModelMap map){
        map.put("menuActivo", "mnuForo");
        return "blog";
    }
    
    @RequestMapping("/registro")
    public String pageRegistration(ModelMap map){
        map.put("menuActivo", "mnuRegistrate");
        return "registration";
    }
    
    @RequestMapping("/terminos")
    public String pageTerms(ModelMap map){
        return "terms";
    }
    
    @RequestMapping("/politica")
    public String pagePolicy(ModelMap map){
        return "privacy";
    }
    
    @RequestMapping(value ="/login")
    public String doLogin() {
        return "login";
    }
    
	@RequestMapping(value="/contacto/sendMessage", method = RequestMethod.POST)
	public String enviarMensajeContacto(ModelMap map){
		
		ResponseDto respuesta = new ResponseDto();
		respuesta.setMessage("Tu mensaje ha sido enviado!!");
		map.put("respuesta", respuesta);
		
		return "contact-us";
		
	}
    
    /** PRIVATE PAGES **/
    
    /** USER PAGES **/
    
    @RequestMapping("/private/user/workspace")
    public String pageUserWorkspace(ModelMap map){
    	map.put("menuActivo", "mnuMisCursos");
        return "user-workspace";
    }
    
    @RequestMapping("/private/user/mundo3d")
    public String pageWorld3D(ModelMap map){
    	map.put("menuActivo", "mnuMundo3D");
        return "world3d";
    }
    
    @RequestMapping("/private/user/claseOnline")
    public String pageClassOnline(ModelMap map){
    	map.put("menuActivo", "mnuClassOnline");
        return "class-online";
    }
    
    /** ADMIN PAGES **/
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @RequestMapping("/private/admin/inicio")
    public String pageAdminInicio(){
    	return "redirect:/private/admin/init";
    }
    
    /** INSTRUCTOR PAGES **/
    @PreAuthorize("hasRole('ROLE_INSTRUCTOR')")
    @RequestMapping("/private/instructor/inicio")
    public String pageInstructorInicio(){
        return "instructor/instructorIndex";
    }
    
}